-
-
Notifications
You must be signed in to change notification settings - Fork 344
add real time face blurring script #411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update the main README.md list of projects section
Hey, I updated the main README.md, let me know if there's anything else to do. Thanks |
This reverts commit 8266a36.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a real-time face blurring tool that uses OpenCV and deep learning to anonymize faces in various media formats. The implementation provides functionality for processing webcam feeds, video files, and static images with adjustable blur strength and confidence thresholds.
- Adds a complete face blurring application with DNN-based face detection
- Provides support for webcam, video, and image processing workflows
- Updates the main README with proper formatting fixes and new script entry
Reviewed Changes
Copilot reviewed 4 out of 6 changed files in this pull request and generated 8 comments.
File | Description |
---|---|
Real-Time-Face-Blurring-Tool/readme | Documentation for the face blurring tool including features, requirements, and installation instructions |
Real-Time-Face-Blurring-Tool/protocol/deploy.prototxt.txt | Caffe model architecture definition file for the face detection neural network |
Real-Time-Face-Blurring-Tool/main.py | Main Python implementation containing face detection, blurring logic, and media processing functions |
README.md | Updates to the main project README with formatting corrections and the new script entry |
Comments suppressed due to low confidence (1)
Real-Time-Face-Blurring-Tool/readme:1
- The filename 'readme' should follow standard conventions and be named 'README.md' for better visibility and markdown rendering.
# Face Blurring Application
|
||
# Extract and blur face ROI | ||
face_roi = image[startY:endY, startX:endX] | ||
blurred_face = cv2.GaussianBlur(face_roi, (blur_strength, blur_strength), 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code doesn't validate that blur_strength is odd, which is required for cv2.GaussianBlur. If an even number is passed, OpenCV will raise an error.
Copilot uses AI. Check for mistakes.
# Extract and blur face ROI | ||
face_roi = image[startY:endY, startX:endX] | ||
blurred_face = cv2.GaussianBlur(face_roi, (blur_strength, blur_strength), 0) | ||
image[startY:endY, startX:endX] = blurred_face |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no validation that the face ROI has non-zero dimensions. If startY >= endY or startX >= endX, this will create an empty array that could cause issues with GaussianBlur.
# Extract and blur face ROI | |
face_roi = image[startY:endY, startX:endX] | |
blurred_face = cv2.GaussianBlur(face_roi, (blur_strength, blur_strength), 0) | |
image[startY:endY, startX:endX] = blurred_face | |
# Validate ROI dimensions | |
if endY > startY and endX > startX: | |
# Extract and blur face ROI | |
face_roi = image[startY:endY, startX:endX] | |
blurred_face = cv2.GaussianBlur(face_roi, (blur_strength, blur_strength), 0) | |
image[startY:endY, startX:endX] = blurred_face |
Copilot uses AI. Check for mistakes.
""" | ||
|
||
# Load and process the image | ||
image = cv2.imread(image_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function doesn't check if cv2.imread successfully loaded the image. If the file doesn't exist or is corrupted, image will be None, causing a crash in blur_faces().
image = cv2.imread(image_path) | |
image = cv2.imread(image_path) | |
if image is None: | |
print(f"Error: Unable to load image from path '{image_path}'. Please check the file path or file integrity.") | |
return |
Copilot uses AI. Check for mistakes.
# Ensure the output file has a valid extension | ||
output_path = os.path.join(output_folder, os.path.splitext(name)[0] + "_blurred.mp4") | ||
|
||
video = cv2.VideoCapture(video_path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function doesn't verify that the video capture was successfully opened. If the video file doesn't exist or is corrupted, this could lead to unexpected behavior.
video = cv2.VideoCapture(video_path) | |
video = cv2.VideoCapture(video_path) | |
if not video.isOpened(): | |
print(f"Error: Unable to open video file {video_path}. Please check the file path or format.") | |
return |
Copilot uses AI. Check for mistakes.
and allows stopping the recording by pressing 'q'. | ||
""" | ||
|
||
video = cv2.VideoCapture(0) # Open webcam |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function doesn't check if the webcam was successfully opened. If no camera is available, this could cause issues in the processing loop.
video = cv2.VideoCapture(0) # Open webcam | |
video = cv2.VideoCapture(0) # Open webcam | |
if not video.isOpened(): | |
print("Error: Unable to access the webcam. Please ensure it is connected and not in use.") | |
return |
Copilot uses AI. Check for mistakes.
def load_face_detection_model(): | ||
"""Loads the pre-trained face detection model.""" | ||
prototxt_path = os.path.join(BASE_DIR, "protocol", "deploy.prototxt.txt") | ||
model_path = os.path.join(BASE_DIR, "model", "res10_300x300_ssd_iter_140000_fp16.caffemodel") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function doesn't validate that the model files exist before attempting to load them. If the files are missing, this will cause a runtime error.
model_path = os.path.join(BASE_DIR, "model", "res10_300x300_ssd_iter_140000_fp16.caffemodel") | |
model_path = os.path.join(BASE_DIR, "model", "res10_300x300_ssd_iter_140000_fp16.caffemodel") | |
# Check if the model files exist | |
if not os.path.exists(prototxt_path): | |
raise FileNotFoundError(f"Prototxt file not found: {prototxt_path}") | |
if not os.path.exists(model_path): | |
raise FileNotFoundError(f"Model file not found: {model_path}") | |
Copilot uses AI. Check for mistakes.
out = cv2.VideoWriter(output_path, fourcc, fps, res) | ||
return out | ||
|
||
def blur_faces(image, confidence_threshold=0.5, blur_strength=61): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The magic number 61 for blur_strength should be defined as a named constant to improve code maintainability and make it easier to adjust.
def blur_faces(image, confidence_threshold=0.5, blur_strength=61): | |
def blur_faces(image, confidence_threshold=0.5, blur_strength=DEFAULT_BLUR_STRENGTH): |
Copilot uses AI. Check for mistakes.
cv2.resize(image, (300, 300)), | ||
1.0, | ||
(300, 300), | ||
(104.0, 177.0, 123.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The magic numbers (300, 300) and (104.0, 177.0, 123.0) should be defined as named constants to improve code readability and maintainability.
cv2.resize(image, (300, 300)), | |
1.0, | |
(300, 300), | |
(104.0, 177.0, 123.0) | |
cv2.resize(image, INPUT_SIZE), | |
1.0, | |
INPUT_SIZE, | |
MEAN_VALUES |
Copilot uses AI. Check for mistakes.
PR Title
Add Real-Time Face Blurring Tool with OpenCV
Summary
summary...
Add the folder containing the script and add the script's information in the Readme file of the project
Description
This PR introduces a real-time face blurring script capable of anonymizing faces in:
-Webcam feeds (live processing)
-Video files (MP4 format)
-Static images (JPG/PNG)
Checks
in the repository
in the PR
Thank You,
Chris Essomba